
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class WebViewUtil {

 static final _browser = _CustomInAppBrowser()
   ..addMenuItem(InAppBrowserMenuItem(
     id: 1,
     title: 'Menu Item 1',
     showAsAction: true,
     order: 2,
     onClick: () { },
   ));

 static final _settings = InAppBrowserClassSettings(
      browserSettings: InAppBrowserSettings(
          hideUrlBar: true,
          toolbarTopBackgroundColor: Colors.white,
          presentationStyle: ModalPresentationStyle.POPOVER
      ),
      webViewSettings: InAppWebViewSettings(isInspectable: kDebugMode)
  );


  static openBrowser(Uri uri){
    _browser.openUrlRequest(
        urlRequest: URLRequest(url: WebUri("https://flutter.dev")),
        settings: _settings);
  }

}

/// 外部webView
class _CustomInAppBrowser extends InAppBrowser {
  @override
  Future onBrowserCreated() async {
    print("Browser Created!");
  }

  @override
  Future onLoadStart(url) async {
    print("Started $url");
  }

  @override
  Future onLoadStop(url) async {
    print("Stopped $url");
  }

  @override
  void onExit() {
    print("Browser closed!");
  }
}